package com.aabte.feignhttp.demo.feign;

import com.aabte.feignhttp.demo.common.ResponseBean;
import com.aabte.feignhttp.demo.common.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Daniel
 */
@RestController
@RequestMapping("/feign")
public class FeignController {

    @Autowired
    private FeignService feignService;

    @GetMapping("/hello")
    public ResponseBean feignHello() {
        return feignService.hello();
    }


    @GetMapping("/user")
    public ResponseBean user() {
        return ResponseBean.success(feignService.user());
    }

    @GetMapping("/user/{name}")
    public ResponseBean userByName(
            @PathVariable("name") String name
    ) {
        return ResponseBean.success(feignService.userByName1(name));
    }

    @GetMapping("/user/url")
    public ResponseBean userByName2(
            @RequestParam String name
    ) {
        return ResponseBean.success(feignService.userByName2(name));
    }

    @PostMapping("/user")
    public ResponseBean addUser(
            @RequestBody User user
    ) {
        return ResponseBean.success(feignService.addUser(user));
    }

    @PutMapping("/user")
    public ResponseBean updateUser(
            @RequestBody User user
    ) {
        return ResponseBean.success(feignService.updateUser(user));
    }

    @DeleteMapping("/user/{id}")
    public ResponseBean deleteUser(
            @PathVariable Integer id
    ) {
        return ResponseBean.success(feignService.deleteUser(id));
    }


}
